<!-- 公司sop配置 -->
<template>
  <dt-modal-edit
    ref="info"
    title="任务责任人节点设置"
    :label-width="100"
    okText="关闭"
    :width="900"
    :cancelFlag="false"
    @cancelData="cancelData"
    @ok="onOk">
    <div class="taskInfo">
      <span class="sp1">任务名称：</span>
      <span class="sp2">{{ currentRow.sopName }}</span>
    </div>
    <div class="taskBj">
      <p>
        对应“审批流”：
        {{ currentRow.processName ? currentRow.processName : '暂无' }}
        <span @click="approvalEidt">编辑</span>
      </p>
      <p style="margin-left: 150px">
        “审批流”对应组织范围：
        {{ currentRow.multiOrgName ? currentRow.multiOrgName : '暂无' }}
        <span @click="orgChange">切换组织</span>
      </p>
    </div>
    <span class="tips">
      <Icon type="md-alert" class="tips_icon" />
      提示：您可将“审批流程”中的“流程节点”设置为“任务责任人”节点。设置后，该节点下的角色或人员将成为本任务的“任务责任人”
    </span>

    <dt-grid ref="table" :onFetch="onFetch" :height="400" />
    <task-approval ref="taskApproval" @chooseTask="chooseTask"></task-approval>
    <!--扣分节点-->
    <deduct-page ref="deductPage" @onSearch="searchFun"></deduct-page>
  </dt-modal-edit>
</template>

<script>
  import sopApi from '@/biz/buildingManagement/sopConfig'
  import columnOpt from '../opt/taskMultiColumn'
  import taskApproval from './taskList.vue'
  import deductPage from './deductPage.vue'
  export default {
    components: { taskApproval,deductPage },
    data() {
      return {
        // title: '任务生成及扣分规则设置',
        info: {},
        isSynchronize: 0,
        btnLoading: false,

        // 3.8
        currentRow: {},
        currentOrg: {},
        processList: [],
        orgList: [],
        isTaskAssess: false,
        isAssess: false,

        columns: []
      }
    },
    methods: {
      chooseTask(val) {
        if (val.fromSource == 'org') {
          this.currentRow.multiOrgId = val.key
          this.currentRow.multiOrgName = val.value
          this.$refs.table.fetch()
        } else {
          this.currentRow.processNo = val.processNo
          this.currentRow.processName = val.processName
          let params = {
            configId: this.currentRow.id,
            processNo: val.processNo
          }
          return sopApi
            .bindProcess(params)
            .then((res) => {
              this.$Message.success('绑定成功')

              this.getMultiPointOrg().then((res) => {
                this.$refs.table.fetch()
              })
            })
            .catch((err) => {
              // this.total = 0
            })
        }
      },
      searchFun(){
        this.$refs.table.fetch()
      },
      // 列表数据
      onFetch() {
        let params = {
          configId: this.currentRow.id,
          orgId: this.currentRow.multiOrgId
        }
        return sopApi
          .getMultiPoint(params)
          .then((res) => {
            return res
          })
          .catch((err) => {})
      },
      orgChange() {
        this.getMultiPointOrg().then((res) => {
          this.$refs.taskApproval.show('org', this.orgList, this.currentRow.multiOrgId)
        })
      },
      approvalEidt() {
        this.manageList().then((res) => {
          this.$refs.taskApproval.show('processList', res, this.currentRow.processNo)
        })
      },
      editNode(row) {
        let rowVal = {
          point: {
            pointId: row.pointId,
            leaderType: row.leaderType,
            roleType: row.roleType,
            configId: this.currentRow.id
          },
          sopName: this.currentRow.sopName
        }
        this.$emit('editNode', rowVal)
      },
      // 获取审批组织
      getMultiPointOrg() {
        let params = {
          configId: this.currentRow.id
        }
        return sopApi
          .getMultiPointOrg(params)
          .then((res) => {
            if (res && res.length) {
              this.orgList = res
              // this.currentRow.multiOrgId = this.orgList[0].orgId
              // this.currentRow.multiOrgName = this.orgList[0].orgName
              this.orgList.forEach((item) => {
                item.key = String(item.orgId)
                item.value = item.orgName
              })
              return this.orgList
            }
          })
          .catch((err) => {})
      },
      manageList() {
        let params = {}
        return sopApi
          .manageList(params)
          .then((res) => {
            this.processList = res
            this.processList.forEach((item) => {
              item.key = String(item.processNo)
              item.value = item.processName
            })
            return this.processList
          })
          .catch((err) => {})
      },

      show(data) {
        this.currentRow = data
        this.$refs.table.init(this, new columnOpt(this))
        this.$refs.info.show()
        if (this.currentRow.processNo && this.currentRow.multiOrgId) {
          this.$refs.table.fetch()
        }
      },
      cancelData() {
        this.$refs.table.emptyGrid()
      },
      onOk() {
        this.$refs.info.hide()
      },
      // 扣分节点
      deductNode(row){
        this.currentRow.leaderMsg = row.leaderMsg
        this.currentRow.pointId = row.pointId
        this.$refs.deductPage.show(this.currentRow)
      }
    }
  }
</script>
<style lang="scss" scoped>
  .taskInfo {
    display: flex;
    flex-wrap: wrap;
    font-size: 16px;
  }

  .taskBj {
    display: flex;
    flex-direction: row;
    margin: 10px 0 10px 20px;

    p {
      span {
        color: #0f42a7;
        cursor: pointer;
      }
    }
  }

  .tips {
    padding: 5px 10px;
    text-align: right;
    line-height: 32px;
    font-size: 14px;
    background: rgba(254, 252, 236, 1);

    .tips_icon {
      font-size: 20px;
      color: #0f42a7;
      vertical-align: sub;
    }
  }
</style>
